/*
 * @author Andre Korzen
 */
package de.uni.muenster.idw2.location.bluetooth.service;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class SaveToDisk {

	/*
	 * save data to SD-Card, folder BT_Tracking
	 * as .csv , separated by tabstop, filename=timestamp
	 * 
	 * example:
	 * 00:19:63:FD:D9:7B	-59
	 * 18:86:AC:D3:26:D0	-67
	 * 
	 */
	public static boolean saveDataToDisk(String timestamp, String dAddress, short dRSSI) {
			String directory = "/sdcard/BTTracking/";
            return saveDataToDisk(directory, timestamp, dAddress, dRSSI);
	}
	
	public static boolean saveDataToDisk(String directory, String timestamp, String dAddress, short dRSSI) {
		try {
			if (!directory.endsWith("/")) directory +="/"; 
			String filename = directory + timestamp +".csv";
			FileWriter testwriter = new FileWriter(filename, true);// true for appending data
			BufferedWriter out = new BufferedWriter(testwriter);
			String s = dAddress+"\t"+dRSSI;
			out.write(s);
			out.newLine();
			out.flush();
			out.close();
			testwriter.close();
		} catch (IOException e) {
			return false;
		}
		return true;
	}
}
